﻿// ParseLib - An open source library for natural language processing.
// Copyright (C) Kais Dukes, 2012. E-mail: kais@kaisdukes.com
// http://parselib.org

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using ParseLib.Tagging;

namespace ParseLib.Corpora
{
    public abstract class Corpus : ICorpus
    {
        public Version Version { get; set; }

        public string Source { get; set; }

        public PartOfSpeechTagset PartOfSpeechTagset { get; protected set; }

        public int TextualUnitCount { get; protected set; }

        public int TokenCount
        {
            get { return this.Sum(x => x.TokenCount); }
        }

        public abstract TextualUnit this[int index] { get; }

        public IEnumerable<IToken> Tokens
        {
            get
            {
                for (var i = 0; i < TextualUnitCount; i++)
                {
                    var textualUnit = this[i];
                    var tokenCount = textualUnit.TokenCount;
                    for (var j = 0; j < tokenCount; j++)
                    {
                        yield return textualUnit[j];
                    }
                }
            }
        }

        public IEnumerator<TextualUnit> GetEnumerator()
        {
            for (var i = 0; i < TextualUnitCount; i++)
            {
                yield return this[i];
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public abstract void Load();
    }
}
